package com.imooc.pan.server.common.utils;

import com.imooc.pan.core.constants.RPanConstants;
import com.imooc.pan.server.modules.user.entity.RPanUser;

import java.util.Objects;

/**
 * 用户id存储工具类
 * @author hhb
 * @data 2024/6/7 20:36
 */

public class UserIdUtil {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void set(Long userId){
        threadLocal.set(userId);
    }

    public static Long get(){
        Long userId = threadLocal.get();
        if(Objects.isNull(userId)){
            userId = RPanConstants.ZERO_LONG;
        }
        return userId;
    }

    public static void remove(){
        threadLocal.remove();
    }
}
